
//
// 101203 - AH - Created.
// 101204a- AH - setForest(Forest).
// 101204b- AH - Added Laetitia as author.
// 101205 - AH - Extends new abstract base class for tests SoekratTestCase.
// 101228 - AH - Minor java doc fix, bug discovered by java doc compiler.
//

package org.soekrat.engine.wheel.test.util;

import java.io.CharArrayWriter;
import java.io.PrintWriter;

import org.soekrat.engine.forest.Forest;
import org.soekrat.engine.forest.Tree;
import org.soekrat.engine.wheel.ontology.ForestOntology;
import org.soekrat.test.SoekratTestCase;

/**
 * <p>
 *   {@link ForestOntology} test case. 
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
public final class ForestSpokeTestCase extends SoekratTestCase
{
  private Forest m_forest=null;
  
  private Forest m_output=null;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param name Test case name.
   */
  public ForestSpokeTestCase(String name){ super(name); }
  
  /**
   * <p>
   *   Sets forest of test case.
   * </p>
   * @param forest {@link Forest}.
   */
  void setForest(Forest forest)
  {
    if (forest==null)
    {
      throw new NullPointerException("forest");
    }
    
    m_forest=new Forest(forest);
  }
  
  /**
   * <p>
   *   Gets 
   *   {@link Forest} of test case.
   * </p>
   * @return {@link Forest} or {@code null} if is missing.
   */
  public Forest getForest(){ return m_forest; }
  
  /**
   * <p>
   *   Sets trees of output.
   * </p>
   * @param forest Trees of output.
   */
  void setOutput(Forest forest)
  {
    if (forest==null)
    {
      throw new NullPointerException("forest");
    }
    
    m_output=new Forest(forest);
  }
  
  /**
   * <p>
   *   Gets 
   *   {@link Tree}s of output.
   * </p>
   * @return {@link Forest} with output trees.
   */
  public Forest getOutput(){ return m_output; }
  
  @Override
  public String toString()
  {
    CharArrayWriter caw=new CharArrayWriter();
    PrintWriter pw=new PrintWriter(caw);
    
    pw.println(super.toString());
    pw.println();
    
    if (m_forest==null) 
    {
      pw.println("No forest!");
    }
    else                
    {
      pw.println("Forest");
      pw.println(m_forest.toString());
    }
    
    if (m_output==null) 
    {
      pw.println("No output!");
    }
    else                
    {
      pw.println("Output");
      pw.println(m_output.toString());
    }
    
    pw.flush();
    return caw.toString();
  }
  
}
